import requests
import json


url1 = 'http://dushu.baidu.com/api/pc/getChapterContent?data={%22book_id%22:%224315647187%22,%22cid%22:%224315647187|10181150%22,%22need_bookinfo%22:1}'
url2 = 'http://dushu.baidu.com/api/pc/getChapterContent?data={%22book_id%22:%224315647187%22,%22cid%22:%224315647187|10181151%22,%22need_bookinfo%22:0}'
url28= 'http://dushu.baidu.com/api/pc/getChapterContent?data={%22book_id%22:%224315647187%22,%22cid%22:%224315647187|10181177%22,%22need_bookinfo%22:1}'
url29= 'http://dushu.baidu.com/api/pc/getChapterContent?data={%22book_id%22:%224315647187%22,%22cid%22:%224315647187|10181178%22,%22need_bookinfo%22:0}'


headers = {
	'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36',
	'Referer': 'http://dushu.baidu.com/pc/reader?gid=4315647187&cid=10181150',
	'Cookie': 'BIDUPSID=DBCD87759C606F9ADCB7B70F4805FEAC; PSTM=1585398330; BAIDUID=DBCD87759C606F9A444CF359AC3D0700:FG=1; H_PS_PSSID=1461_21106_31254_31186_31229_30824_31164_22157; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BDSFRCVID=jgDsJeCCxG3HBdJurKvtLXj15cBTF9vvRq-x3J; H_BDCLCKID_SF=tJAj_D-btK03fP36qR6sMJ8thmT22-us2DvRQhcH0hOWsIOSL4Ok5JDU5lOrXPIDJC7G-pLXbtQCqj69DUC0-nDSHH8Ot5tq3J; Hm_lvt_bf1e478a71b02a743ab42bcfed9d1ff1=1586782808,1586783014; Hm_lpvt_bf1e478a71b02a743ab42bcfed9d1ff1=1586783388'
}

resp = requests.get(url29,headers = headers)
# print(resp.text)
resp_json = json.loads(resp.text)
# print(resp_json['data']['novel']['content'])
text = resp_json['data']['novel']['content']
# content = text.replace('\r','')
# content = text.replace('\n','')
print(text)
with open('从前有座灵剑山.txt','w',encoding='utf-8') as f:
	f.write(text)
	f.close()